package com.sskj.wallet.ui.activity;


import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.util.CopyUtil;
import com.sskj.lib.util.ImageUtil;
import com.sskj.wallet.R;
import com.sskj.wallet.R2;
import com.sskj.wallet.bean.RecordInfoBean;
import com.sskj.wallet.bean.TransferRecordBean;
import com.sskj.wallet.presenter.RecordInfoActivityPresenter;

import java.util.HashMap;

import butterknife.BindView;

@Route(path = RConfig.WALLET_RECORD_INFO)//交易记录
public class RecordInfoActivity extends BaseActivity<RecordInfoActivityPresenter> {
    @Autowired
    TransferRecordBean data;
    @BindView(R2.id.ivStatus)
    ImageView ivStatus;
    @BindView(R2.id.tvStatus)
    TextView tvStatus;
    @BindView(R2.id.tvPrice)
    TextView tvPrice;
    @BindView(R2.id.tvToAddress)
    TextView tvToAddress;
    @BindView(R2.id.ivCopyToAddress)
    ImageView ivCopyToAddress;
    @BindView(R2.id.tvFromAddress)
    TextView tvFromAddress;
    @BindView(R2.id.ivCopyFromAddress)
    ImageView ivCopyFromAddress;
    @BindView(R2.id.ivCopyFromAddressHash)
    ImageView ivCopyFromAddressHash;
    @BindView(R2.id.tvMinerFee)
    TextView tvMinerFee;
    @BindView(R2.id.tvMinerFeeDesc)
    TextView tvMinerFeeDesc;
    @BindView(R2.id.tvMemo)
    TextView tvMemo;
    @BindView(R2.id.tvTransNo)
    TextView tvTransNo;
    @BindView(R2.id.tvBlock)
    TextView tvBlock;
    @BindView(R2.id.tvCreateTime)
    TextView tvCreateTime;
    @BindView(R2.id.ivQRCode)
    ImageView ivQRCode;
    @BindView(R2.id.btCopy)
    Button btCopy;
    @Autowired
    String hash;
    @Autowired
    String type;

    @Override
    protected int getLayoutId() {
        return R.layout.wallet_activity_record_info;
    }

    @Override
    public RecordInfoActivityPresenter getPresenter() {
        return new RecordInfoActivityPresenter();
    }

    @Override
    protected void initView() {
        setTitle(App.INSTANCE.getString(R.string.wallet_recordInfoActivity1_j));
        ARouter.getInstance().inject(this);
        mPresenter.getData(hash);

    }

    public void updateUI(RecordInfoBean data) {
        HashMap<String, Integer> statusMap = new HashMap<>();
        statusMap.put("Success", R.mipmap.wallet_icon_transfer_success);
        statusMap.put("Fail", R.mipmap.wallet_icon_transfer_fail);
        ImageUtil.setImage(statusMap.get(data.getIsSuccess()), ivStatus);
        tvStatus.setText(type.equals("1") ? App.INSTANCE.getString(R.string.wallet_recordInfoActivity2_j) : App.INSTANCE.getString(R.string.wallet_recordInfoActivity3_j));
        tvPrice.setText((type.equals("1") ? "-" : "+") + this.data.getPrice() + this.data.getPtype());
        tvFromAddress.setText(data.getFrom());
        ClickUtil.click(ivCopyFromAddress, () -> {
            CopyUtil.copy(data.getFrom());
        });
        tvToAddress.setText(data.getTo());
        ClickUtil.click(ivCopyToAddress, () -> {
            CopyUtil.copy(data.getTo());
        });
        tvMinerFee.setText(data.getTxFee());
        tvMinerFeeDesc.setText(String.format("=Gas(%s)*GasPrice(%s)", data.getGasUsed(), data.getGasPrice()));

        tvMemo.setText(data.getMemo());
        tvTransNo.setText(data.getTxHash());
        tvBlock.setText(data.getBlockNumber());
        tvCreateTime.setText(data.getTimestamp());
        ClickUtil.click(ivCopyFromAddressHash, () -> {
            CopyUtil.copy(data.getTxHash());
        });
    }

}
